﻿#include "ffmpeg.h"

int ffmpeg::ImagetoVideo(const char* imagePath, const char* imageFormat, const char* videoPath, unsigned rawFrameRates, unsigned outputFrameRates, unsigned kbps)
{
	char BUF[MAXBUFLEN];
	if (kbps)
		snprintf(BUF, MAXBUFLEN,
			"\"%s\"ffmpeg.exe -r %u  -f image2 -i %s\\%%05d.%s -b:v %uK -vcodec libx264  -r %u %s",	//%05d05ȥ
			ffmpegPath, rawFrameRates, imagePath, imageFormat, kbps, outputFrameRates, videoPath);
	else
		snprintf(BUF, MAXBUFLEN,
			"\"%s\"ffmpeg.exe -r %u -f image2 -i %s\\%%05d.%s  -vcodec libx264 -r %u %s",
			ffmpegPath, rawFrameRates, imagePath, imageFormat, outputFrameRates, videoPath);
	return system(BUF);
}

int ffmpeg::VideotoImage(const char* videoPath, const char* imagePath, const char* imageFormat)
{
	char BUF[MAXBUFLEN];
	snprintf(BUF, MAXBUFLEN, "md %s", imagePath);
	system(BUF);
	snprintf(BUF, MAXBUFLEN,
		"\"%s\"ffmpeg.exe -i %s -q:v 2 -f image2  %s\\%%05d.%s",
		ffmpegPath, videoPath, imagePath, imageFormat);
	return system(BUF);
}

/*
int ffmpeg::test()
{
	bool tag = ImagetoVideo(testPath, "png", "out.mp4", 30, 30);
	if (tag) return tag;
	tag = VideotoImage("out.mp4", testPath, "png");
	return tag;
}
*/